#!/bin/bash
#对比龙芯提交与社区linux仓库commit提交的区别
#龙芯范围：4.19.74-4.19.152
gitloong=/home/lindorx/mydir/git/uos/kernel/UOS-kernel-4.19-loongson
gitbase=/home/lindorx/mydir/git/uos/kernel/linux

commit_start_end="9a81a521aa56..a4dd372a0c76"

gitloong_log_all=`cd ${gitloong} && git log --oneline --reverse ${commit_start_end}`
gitbase_log_all=`cd ${gitbase} && git log --oneline --reverse dbc29aff8d04..HEAD`

IFS=$'\n'
OLDIFS='$IFS'

loongdir="loongson"
basedir="linux"

mkdir -p $loongdir $basedir

echo "开始匹配"
start_number=1
for i in ${gitloong_log_all[@]}
do
    commit_msg=${i#* }
    commit_id=${i%% *}
    loongson_md5id=`GIT_DIR=$gitloong/.git git show $commit_id --oneline | awk 'NR>1' | grep -v "^index.*\.\..*" | md5sum | awk '{print$1}'`

    base_commit=`echo "${gitbase_log_all}" | grep -w -m1 "${commit_msg}"`
    base_commit_id=${base_commit%% *}
    base_md5id=`GIT_DIR=$gitbase/.git git show $base_commit_id --oneline | awk 'NR>1' | grep -v "^index.*\.\..*" | md5sum | awk '{print$1}'`
    #echo $loongson_md5id--$base_md5id

    if [ "$loongson_md5id" != "$base_md5id" ]; then
        echo $start_number
        GIT_DIR=$gitbase/.git git format-patch -o $basedir -1 --start-number=$start_number $base_commit_id >> /dev/null 
        GIT_DIR=$gitloong/.git git format-patch -o $loongdir -1 --start-number=$start_number $commit_id >> /dev/null
        let start_number+=1
    fi
done